﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HeadFirst.SimpleFactory
{
    class SimpleFacMain
    {
        /*
         * 简单工厂模式，通过抽象对象后，统一创建实体的地方
         1、注意函数，字段，类名门
         2、注意 垂直，水平格式，区段分明
         3、视图和逻辑分离。 
         4、低耦合，高内聚。 单一职责原则
        */
        static void Main(string[] args)
        {
            Console.WriteLine("输入数1:");
            float firstParam = float.Parse(Console.ReadLine());

            Console.WriteLine("输入运算符:");
            string operationType = Console.ReadLine();

            Console.WriteLine("输入数2:");
            float secondParam = float.Parse(Console.ReadLine());

            float operation = GetResult(firstParam, operationType, secondParam);
            Console.WriteLine("Result:" + operation);

            Console.WriteLine("按任意键退出!");
            Console.ReadKey();
        }

        private static float GetResult(float firstParam, string operationType, float secondParam)
        {
            BaseOperation operation = CalcBusiness.CreateOperation(operationType);
            operation.FirstParams = firstParam;
            operation.SecondParams = secondParam;
            return operation.Operation();
        }
    }
}
